const api = {
  acmAuth: {
    org: {
      getAllEnableTree: 'getAllEnableTree'
    },
    user: {
      queryAllUserInfo: 'queryAllUserInfo',
      getOrgUserPage: 'getOrgUserPage'
    }
  },
  acmMdm: {
    sysComponent: { config: { query: 'query' } },
    projCategory: { getAllTree: 'getAllTree' },
    SysDictDefinition: { queryItemByCode: 'queryItemByCode' },
    expenditureMatters: { queryListByProjCategory: 'queryListByProjCategory' },
    attachment: {
      upload: 'upload',
      download: 'download',
      getAttInfo: 'getAttInfo',
      getAttIdData: 'getAttIdData',
      getAttInfoByDomainCode: 'getAttInfoByDomainCode',
      noAuth: {
        download: 'download'
      }
    },
    attachmentConfig: { query: 'query' },
    operationAuditLog: {
      findOperationAuditLogById: 'findOperationAuditLogById',
      saveBatch: 'saveBatch'
    },
    area: {
      getTree: 'getTree'
    }
  },
  acmProjlib: {
    projApply: { applyProjQueryPage: 'applyProjQueryPage' },
    projectProofRegister: {
      getList: 'getList'
    },
    projectDesign: {
      queryProjectApplyListWithAlternateType: 'queryProjectApplyListWithAlternateType'
    }
  },
  acmEngineering: {
    engineering: {
      initiation: {
        queryPage: 'queryPage',
        queryById: 'queryById',
        update: 'update',
        saveEngineeringInfo: 'saveEngineeringInfo',
        getProposalInfo: 'getProposalInfo',
        saveProposalInfo: 'saveProposalInfo',
        saveSpecialInfo: 'saveSpecialInfo',
        getSpecialInfo: 'getSpecialInfo',
        getBudgetInfo: 'getBudgetInfo',
        saveBudgetInfo: 'saveBudgetInfo',
        getPerfTargetInfo: 'getPerfTargetInfo',
        savePerfTargetInfo: 'savePerfTargetInfo',
        saveAttInfo: 'saveAttInfo',
        delete: 'delete',
        getEngineeringInfo: 'getEngineeringInfo',
        saveEngineering: 'saveEngineering',
        submitDesignProject: 'submitDesignProject',
        exportExcel: 'exportExcel',
        repealDesignProject: 'repealDesignProject'
      },
      ledger: {
        getEngineeringInfo: 'getEngineeringInfo'
      }
    },
    expendConfig: {
      engineeringExpendItemConfig: { getConfigData: 'getConfigData' }
    },
    progressInfo: {
      engineeringprogressstartinfo: {
        queryPage: 'queryPage',
        save: 'save',
        getListPage: 'getListPage',
        queryById: 'queryById',
        getAllInfo: 'getAllInfo',
        exportExcel: 'exportExcel',
        saveProgressInfo: 'saveProgressInfo',
        submit: 'submit',
        delete: 'delete',
        repeal: 'repeal',
        selectPageProjectByStart: 'selectPageProjectByStart'
      }
    },
    biddingApply: {
      engineeringbiddingapply: {
        queryPage: 'queryPage',
        save: 'save',
        getListPage: 'getListPage',
        queryById: 'queryById',
        getAllInfo: 'getAllInfo',
        exportExcel: 'exportExcel',
        saveBiddingApply: 'saveBiddingApply',
        queryInfoById: 'queryInfoById',
        submit: 'submit',
        delete: 'delete',
        repeal: 'repeal',
        selectPageProjectByBidding: 'selectPageProjectByBidding'
      }
    },
    projectConclusion: {
      engineeringprojectconclusion: {
        queryPage: 'queryPage',
        save: 'save',
        getListPage: 'getListPage',
        queryById: 'queryById',
        getAllInfo: 'getAllInfo',
        exportExcel: 'exportExcel',
        saveInfo: 'saveInfo',
        queryInfoById: 'queryInfoById',
        submit: 'submit',
        delete: 'delete',
        repeal: 'repeal',
        selectPageProjectByConclusion: 'selectPageProjectByConclusion'
      }
    },
    plan: {
      engineeringPlan: {
        queryPage: 'queryPage',
        queryById: 'queryById',
        update: 'update',
        add: 'add',
        getEngineeringPlanInfo: 'getEngineeringPlanInfo',
        saveAttInfo: 'saveAttInfo',
        delete: 'delete',
        commit: 'commit',
        exportExcel: 'exportExcel',
        repeal: 'repeal'
      }
    },
    progressReport: {
      engineeringProgressReport: {
        queryPage: 'queryPage',
        queryById: 'queryById',
        save: 'save',
        getEngineeringProgressReportInfo: 'getEngineeringProgressReportInfo',
        saveAttInfo: 'saveAttInfo',
        delete: 'delete',
        commit: 'commit',
        exportExcel: 'exportExcel',
        repeal: 'repeal'
      }
    },
    engineeringReceivingInfo: {
      getList: 'getList',
      save: 'save',
      findApplyInfoById: 'findApplyInfoById',
      submit: 'submit',
      deleteApplyInfo: 'deleteApplyInfo',
      repeal: 'repeal',
      selectPage4CloseProject: 'selectPage4CloseProject'
    },
    projectChange: {
      queryPage: 'queryPage',
      saveEngineeringInfo: 'saveEngineeringInfo',
      saveAttInfo: 'saveAttInfo',
      delete: 'delete',
      getAllChangeInfo: 'getAllChangeInfo',
      saveChangeInfo: 'saveChangeInfo',
      submitDesignProject: 'submit',
      exportExcel: 'exportExcel',
      repeal: 'repeal'
    }
  },
  acmHouse: {
    houseBuildingInfoConfig: {
      getList: 'getList',
      save: 'save',
      getAllTree: 'getAllTree',
      deleteApplyInfo: 'deleteApplyInfo',
      updateSate: 'updateSate',
      exportList: 'exportList'
    },
    houseBuildingRoomInfoConfig: {
      getList: 'getList',
      save: 'save',
      updateSate: 'updateSate',
      deleteApplyInfo: 'deleteApplyInfo',
      exportList: 'exportList'
    },
    houseBuildingRoomApply: {
      getList: 'getList',
      submit: 'submit',
      deleteApplyInfo: 'deleteApplyInfo',
      exportList: 'exportList',
      findApplyInfoById: 'findApplyInfoById',
      findApplyInfoByCondition: 'findApplyInfoByCondition',
      exportLedgerList: 'exportLedgerList',
      save: 'save',
      repeal: 'repeal'
    },
    houseBuildingRoomAssign: {
      getList: 'getList',
      submit: 'submit',
      deleteApplyInfo: 'deleteApplyInfo',
      exportList: 'exportList',
      findApplyInfoById: 'findApplyInfoById',
      save: 'save',
      repeal: 'repeal'
    },
    housebuildingroomtermination: {
      queryInfoPage: 'queryInfoPage',
      submit: 'submit',
      delete: 'delete',
      export: 'export',
      save: 'save',
      repeal: 'repeal',
      queryById: 'queryById',
      getApplyId: 'getApplyId'
    }
  },
  acmBus: {
    busapplyinfo: {
      queryPage: 'queryPage',
      getArrangeList: 'getArrangeList',
      add: 'add',
      delete: 'delete',
      queryById: 'queryById',
      distributeCar: 'distribute',
      distributeDriver: 'distributeDriver',
      getLedger: 'getLedger',
      getDistributeDetail: 'getDistributeDetail',
      update: 'update',
      submit: 'submit',
      updateKilometers: 'updateKilometers',
      driverSubmit: 'driverSubmit',
      driverRepeal: 'driverRepeal',
      repeal: 'repeal'
    },
    projectChange: {
      //公车司机信息管理
      busdriverinfo: {
        queryPage: 'queryPage',
        add: 'add',
        delete: 'delete',
        queryById: 'queryById',
        list: 'list',
        save: 'save',
        update: 'update',
        export: 'export'
      },
      //公车车辆信息管理
      buscarinfo: {
        queryPage: 'queryPage',
        add: 'add',
        delete: 'delete',
        queryById: 'queryById',
        list: 'list',
        save: 'save',
        update: 'update',
        export: 'export'
      }
    }
  }
}

function toUnderline(str: string, level: number) {
  if (level > 1) {
    return str
  }
  return str.replace(/([A-Z])/g, '-$1').toLowerCase()
}
function setApiPrefix(api: Record<string, any>, prefix = '', level = 0) {
  for (const key in api) {
    if (typeof api[key] === 'object' && api[key] !== null) {
      setApiPrefix(
        api[key],
        (level == 0 ? '/api' : '') + toUnderline(prefix, level) + '/' + (api.key || key),
        level + 1
      )
    } else {
      api[key] = prefix + (api[key].startsWith('/') ? api[key] : '/' + api[key])
    }
  }
}
setApiPrefix(api)

export default api
